package net.sf.flock.webapp.tree;
import net.sf.tapestry.IAsset;
import net.sf.tapestry.IMarkupWriter;
import net.sf.tapestry.IRequestCycle;
import net.sf.tapestry.RequestCycleException;
import net.sf.tapestry.html.Body;
public class XTree extends Tree {
private final static String[] ICONS = new String[] {
"rootIcon",
"openRootIcon",
"folderIcon",
"openFolderIcon",
"fileIcon",
"iIcon",
"lIcon",
"lMinusIcon",
"lPlusIcon",
"tIcon",
"tMinusIcon",
"tPlusIcon",
"blankIcon"
};
/**
* @see net.sf.tapestry.AbstractComponent#renderComponent(IMarkupWriter, IRequestCycle)
*/
protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle) throws RequestCycleException {
// get Body and contribute script asset
Body body = Body.get(cycle);
IAsset script = this.getAsset("xtreeScript");
body.includeScript( script.buildURL(cycle) );
writer.printRaw("<link rel='stylesheet' type='text/css' href='" + this.getAsset("xtreeStylesheet").buildURL(cycle) +"'/>");
writer.begin("script");
writer.attribute("language", "JavaScript");
writer.print("if (document.getElementById) {\n");
// generate tree config
writer.print("webFXTreeConfig = {\n");
for (int i=0; i<ICONS.length; i++) {
String url = this.getAsset( ICONS[i] ).buildURL(cycle);
body.getPreloadedImageReference( url );
writer.printRaw( ICONS[i] + ": '" + url + "',\n" );
}
writer.print("defaultText : 'Tree Item',\n");
writer.print("defaultAction : 'javascript:void(0);',\n");
writer.print("defaultBehavior : 'classic'\n");
writer.print("};\n");
super.renderComponent(writer, cycle);
writer.print("document.write(t1); }");
writer.end();
* @see net.sf.flock.webapp.tree.Tree#renderCurrentNode(IMarkupWriter, IRequestCycle)
protected void renderCurrentNode(IMarkupWriter writer, IRequestCycle cycle) throws RequestCycleException {
if (this.getDepth()==1) {
writer.print( "t1 = new WebFXTree('" + this.getValue().getId() + "');\n");
} else {
writer.print( "t" + this.getDepth() +" = new WebFXTreeItem('" + this.getValue().getId() + "');\n");
writer.print( "t" + (this.getDepth()-1)+".add( t" + this.getDepth() + " );\n" );